home *** CD-ROM | disk | FTP | other *** search
-
-
-
- SSSSEEEETTTTJJJJMMMMPPPP((((3333CCCC)))) SSSSEEEETTTTJJJJMMMMPPPP((((3333CCCC))))
-
-
-
- NNNNAAAAMMMMEEEE
- setjmp, longjmp, sigsetjmp, siglongjmp, _setjmp, _longjmp - non-local
- gotos
-
- SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
- ####iiiinnnncccclllluuuuddddeeee <<<<sssseeeettttjjjjmmmmpppp....hhhh>>>>
-
- _S_y_s_V:
- iiiinnnntttt sssseeeettttjjjjmmmmpppp ((((jjjjmmmmpppp____bbbbuuuuffff eeeennnnvvvv))));;;;
-
- vvvvooooiiiidddd lllloooonnnnggggjjjjmmmmpppp ((((jjjjmmmmpppp____bbbbuuuuffff eeeennnnvvvv,,,, iiiinnnntttt vvvvaaaallll))));;;;
-
- _P_O_S_I_X:
- iiiinnnntttt ssssiiiiggggsssseeeettttjjjjmmmmpppp ((((ssssiiiiggggjjjjmmmmpppp____bbbbuuuuffff eeeennnnvvvv,,,, iiiinnnntttt ssssaaaavvvveeeemmmmaaaasssskkkk))));;;;
-
- vvvvooooiiiidddd ssssiiiigggglllloooonnnnggggjjjjmmmmpppp ((((ssssiiiiggggjjjjmmmmpppp____bbbbuuuuffff eeeennnnvvvv,,,, iiiinnnntttt vvvvaaaallll))));;;;
-
- _B_S_D:
- iiiinnnntttt sssseeeettttjjjjmmmmpppp ((((jjjjmmmmpppp____bbbbuuuuffff eeeennnnvvvv))));;;;
-
- vvvvooooiiiidddd lllloooonnnnggggjjjjmmmmpppp ((((jjjjmmmmpppp____bbbbuuuuffff eeeennnnvvvv,,,, iiiinnnntttt vvvvaaaallll))));;;;
-
- iiiinnnntttt ____sssseeeettttjjjjmmmmpppp ((((jjjjmmmmpppp____bbbbuuuuffff eeeennnnvvvv))));;;;
-
- vvvvooooiiiidddd ____lllloooonnnnggggjjjjmmmmpppp ((((jjjjmmmmpppp____bbbbuuuuffff eeeennnnvvvv,,,, iiiinnnntttt vvvvaaaallll))));;;;
-
- To use the BSD versions of _s_e_t_j_m_p and _l_o_n_g_j_m_p, you must either
-
- 1) #define ____BBBBSSSSDDDD____SSSSIIIIGGGGNNNNAAAALLLLSSSS or ____BBBBSSSSDDDD____CCCCOOOOMMMMPPPPAAAATTTT before including <_s_e_t_j_m_p._h>, or
-
- 2) specify one of them in the compile command or makefile:
-
- cc -D_BSD_SIGNALS -o prog prog.c
-
-
- DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
- These functions are useful for dealing with errors and interrupts
- encountered in a low-level subroutine of a program.
-
- All varieties of _s_e_t_j_m_p save their stack environment in _e_n_v (whose type,
- _j_m_p__b_u_f, is defined in the <_s_e_t_j_m_p._h> header file) for later use by all
- varieties of _l_o_n_g_j_m_p. If the return is from a direct invocation, all
- _s_e_t_j_m_ps return the value 0. If the return is from a call to any of the
- _l_o_n_g_j_m_ps, all _s_e_t_j_m_p routines return a nonzero value.
-
- All _l_o_n_g_j_m_ps restore the environment saved by the last call of _s_e_t_j_m_p
- with the corresponding _e_n_v argument. After the _l_o_n_g_j_m_p is completed,
- program execution continues as if the corresponding call of _s_e_t_j_m_p (which
- must not itself have returned in the interim) had just returned the value
- _v_a_l. _l_o_n_g_j_m_ps cannot cause _s_e_t_j_m_ps to return the value 0. If a _l_o_n_g_j_m_p
- is invoked with a second argument of 0, all versions of _s_e_t_j_m_p will
- return 1. At the time of the second return from a _s_e_t_j_m_p, external and
-
-
-
- PPPPaaaaggggeeee 1111
-
-
-
-
-
-
- SSSSEEEETTTTJJJJMMMMPPPP((((3333CCCC)))) SSSSEEEETTTTJJJJMMMMPPPP((((3333CCCC))))
-
-
-
- static variables have values as of the time _l_o_n_g_j_m_p is called (see
- example). The values of register and automatic variables are undefined.
- Register or automatic variables whose value must be relied upon must be
- declared as volatile.
-
- SSSSYYYYSSSSVVVV----PPPPOOOOSSSSIIIIXXXX----BBBBSSSSDDDD DDDDIIIIFFFFFFFFEEEERRRREEEENNNNCCCCEEEESSSS
- The System V _s_e_t_j_m_p/_l_o_n_g_j_m_p perform identically to the 4.3BSD
- __s_e_t_j_m_p/__l_o_n_g_j_m_p, i.e., they manipulate only the C stack and registers.
- The 4.3BSD _s_e_t_j_m_p/_l_o_n_g_j_m_p also manipulate the C stack and registers, but
- additionally save and restore the process's signal mask (see
- _s_i_g_p_r_o_c_m_a_s_k(2), _s_i_g_b_l_o_c_k(3B), or _s_i_g_s_e_t_m_a_s_k(3B)). The POSIX
- _s_i_g_s_e_t_j_m_p/_s_i_g_l_o_n_g_j_m_p calls may act in either manner: the C stack and
- registers are always saved and restored, but if the _s_a_v_e_m_a_s_k parameter to
- _s_i_g_s_e_t_j_m_p is non-zero, the signal mask is saved, and a bit in _e_n_v is set
- to indicate that it was saved. _s_i_g_l_o_n_g_j_m_p checks that bit to determine
- if it should restore the mask or not.
-
- NNNNOOOOTTTTEEEE
- Prior to IRIX 6.5.15, the man page incorrectly stated that the return
- type for the BSD _l_o_n_g_j_m_p(_3_C) and __l_o_n_g_j_m_p(_3_C) was _i_n_t; the correct return
- type is _v_o_i_d.
-
- EEEEXXXXAAAAMMMMPPPPLLLLEEEE
- #include <setjmp.h>
- jmp_buf env;
- int i = 0;
- main ()
- {
- if (setjmp(env) != 0) {
- (void) printf("2nd return from setjmp: i = %d\n", i);
- exit(0);
- }
- (void) printf("1st return from setjmp: i = %d\n", i);
- i = 1;
- g();
- /*NOTREACHED*/
- }
-
- g()
- {
- longjmp(env, 1);
- /*NOTREACHED*/
- }
-
-
- The program's output is:
-
- 1st return from setjmp: i = 0
- 2nd return from setjmp: i = 1
-
-
-
-
- PPPPaaaaggggeeee 2222
-
-
-
-
-
-
- SSSSEEEETTTTJJJJMMMMPPPP((((3333CCCC)))) SSSSEEEETTTTJJJJMMMMPPPP((((3333CCCC))))
-
-
-
- SSSSEEEEEEEE AAAALLLLSSSSOOOO
- sigaction(2), sigprocmask(2), signal(2), sigblock(3B), sigsetmask(3B),
- sigvec(3B), signal(3B).
-
- WWWWAAAARRRRNNNNIIIINNNNGGGGSSSS
- If _l_o_n_g_j_m_p is called even though _e_n_v was never primed by a call to
- _s_e_t_j_m_p, or when the last such call was in a function which has since
- returned, absolute chaos is guaranteed.
-
- In multithreaded processes, if _l_o_n_g_j_m_p is called with an _e_n_v initialized
- in different thread, the result is also guaranteed to produce chaos.
- Also note that the signal mask manipulated by these interfaces is per
- thread.
-
- If different versions of these jmp routines are mixed, unpredictable
- signal masking may occur.
-
- BBBBUUUUGGGGSSSS
- The values of the registers on the second return from the _s_e_t_j_m_p_s are the
- register values at the time of the first call to _s_e_t_j_m_p, not those at the
- time of the _l_o_n_g_j_m_p. This means that variables in a given function may
- behave differently in the presence of _s_e_t_j_m_p, depending on whether they
- are register or stack variables.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- PPPPaaaaggggeeee 3333
-
-
-
-